package com.laboratory.asynctasklearning.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

@Service
public class UserService {

    @Async
    public CompletableFuture<String> findUserById(String userId) {
        System.out.println(Thread.currentThread().getName() + " 开始查询用户: " + userId);
        try {
            Thread.sleep(2000); // 模拟耗时
        } catch (InterruptedException e) {
            System.out.println(e.getMessage());
        }
        System.out.println(Thread.currentThread().getName() + " 查询用户完成: " + userId);
        return CompletableFuture.completedFuture("用户: " + userId);
    }

}
